package microservicedemo.bookservice.controller;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import microservicedemo.bookservice.mapper.BookMapper;
import microservicedemo.bookservice.po.Book;
import org.springframework.web.bind.annotation.*;

@AllArgsConstructor
@RestController
@Slf4j
public class BookController {

    private final BookMapper bookMapper;

    @PostMapping("/addBook")
    public boolean addBook(@RequestBody Book book) {
        bookMapper.addBook(book);
        return true;
    }

    @PostMapping("/delBook")
    public boolean delBook(@RequestBody Book book) {
        bookMapper.delBook(book);
        return true;
    }

    @PutMapping("/editBook")
    public boolean editBook(@RequestBody Book book) {
        bookMapper.editBook(book);
        return true;
    }

    @GetMapping("/getByTitle")
    public Book getByTitle(@RequestParam(value = "title") String title) {
        System.out.println("get by title");
        return bookMapper.getByTitle(title);
    }

    @GetMapping("/getByAuthor")
    public Book getByAuthor(@RequestParam(value = "author") String author) {
        System.out.println("get by author");
        System.out.println(author);
        return bookMapper.getByAuthor(author);
    }
}
